#include "wap_iconlist.h"
#include "wa_wm.h"
#include "wa_win.h"
#include "wa_screen.h"
#include "wa_iconlist.h"
#include "wap.h"

static void wap_iconlist_create(void);
static void wap_iconlist_del(void);
static void wap_iconlist_callback(wa_sign* sign);

wa_screen_obj wap_iconlist_screen = 
{
	.id = WAP_WIN_ICONLIST_ID,
	.create = wap_iconlist_create,
	.del = wap_iconlist_del,
};

wa_obj* wap_iconlist_win;
wa_obj* wap_iconlist_iconlist;

extern wa_bitmap img_icon_camera;
extern wa_bitmap img_icon_clock;
extern wa_bitmap img_icon_graph;
extern wa_bitmap img_icon_interface;
extern wa_bitmap img_icon_light;
extern wa_bitmap img_icon_setting;
extern wa_bitmap img_icon_signal;
extern wa_bitmap img_icon_user;
extern wa_bitmap img_icon_volume;

extern wa_font font_song_16_ascii;

uint8_t wap_iconlist_select;

void wap_iconlist_init(void)
{
	wap_iconlist_select = 0;
}

static void wap_iconlist_create(void)
{
	wap_iconlist_win = wa_win_create(NULL);
	wa_win_set_pos(wap_iconlist_win, 0, 0);
	wa_win_set_size(wap_iconlist_win, WA_LCD_W, WA_LCD_H);
	wa_win_set_edge_show(wap_iconlist_win, wa_nok);
	wa_win_set_callback(wap_iconlist_win, wap_iconlist_callback);
	wap_iconlist_screen.win = wap_iconlist_win;
	
	wap_iconlist_iconlist = wa_iconlist_create(NULL);
	wa_win_add_obj(wap_iconlist_win, wap_iconlist_iconlist);
	wa_obj_set_pos(wap_iconlist_iconlist, 0, 0);
	wa_obj_set_size(wap_iconlist_iconlist, 128, 64);
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_camera, "camera");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_clock, "clock");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_graph, "graph");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_interface, "interface");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_setting, "setting");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_light, "light");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_signal, "signal");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_user, "user");
	wa_iconlist_add_option(wap_iconlist_iconlist, &img_icon_volume, "volume");
	wa_iconlist_set_switch_time_length(wap_iconlist_iconlist, 500);
	wa_iconlist_set_roll_type(wap_iconlist_iconlist, WA_ICONLIST_ROLL_TYPE_HOR);
	wa_iconlist_set_text_font(wap_iconlist_iconlist, &font_song_16_ascii);
	wa_iconlist_set_space(wap_iconlist_iconlist, 40);
	wa_iconlist_set_roll_rect(wap_iconlist_iconlist, 48, 8, 32, 32);
	wa_iconlist_set_text_type(wap_iconlist_iconlist, WA_ICONLIST_TEXT_TYPE_NORMAL_HOR);
	wa_iconlist_set_text_pos(wap_iconlist_iconlist, 0, 0, 0, 44);
	wa_iconlist_set_arrow_enable(wap_iconlist_iconlist, wa_ok);
	wa_iconlist_set_arrow_size(wap_iconlist_iconlist, 8, 16, 16);
	wa_iconlist_set_select(wap_iconlist_iconlist, wap_iconlist_select);
	wa_iconlist_init_select_pos(wap_iconlist_iconlist);
	wa_iconlist_set_anim_enable(wap_iconlist_iconlist, wa_ok);
}

static void wap_iconlist_del(void)
{
	wa_obj_del(wap_iconlist_win);
}

static void _wap_iconlist_paint(wa_obj* obj)
{
}

static void wap_iconlist_callback(wa_sign* sign)
{
	int sign_id;
	wa_obj* obj;
	sign_id = sign->sign_id;
	obj = sign->obj_dst;

	switch (sign_id)
	{
		case WA_SIGNAL_PAINT:
		{
			_wap_iconlist_paint(obj);
			break;
		}
		case WA_SIGNAL_NOTIFY_PARENT:
		{	
			break;
		}
		case WA_SIGNAL_USER_KEY_LEFT:
		{	
			if(wap_iconlist_select > 0)
			{
				wap_iconlist_select--;
			}
			wa_iconlist_set_select(wap_iconlist_iconlist, wap_iconlist_select);
			break;
		}
		case WA_SIGNAL_USER_KEY_RIGHT:
		{	
			if(wap_iconlist_select < 9)
			{
				wap_iconlist_select++;
			}
			wa_iconlist_set_select(wap_iconlist_iconlist, wap_iconlist_select);
			break;
		}
		case WA_SIGNAL_USER_KEY_ESC:
		{	
			wa_screen_switch(WAP_WIN_MENU_ID, WA_SCREEN_SWITCH_TYPE_LEFT_TOGETHER, 500, wa_nok, wa_nok);
			break;
		}
		default:
		{
			break;
		}
	}
}
